package io.renren.modules.origin.controller;
import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.origin.entity.OriginEntity;
import io.renren.modules.origin.service.OriginService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
@RestController
@RequestMapping("origin/origin")
public class OriginController {
    @Autowired
    private OriginService originService;

    @RequestMapping("/list")
    @RequiresPermissions("origin:origin:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = originService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/info/{originNo}")
    @RequiresPermissions("origin:origin:info")
    public R info(@PathVariable("originNo") Integer originNo){
		OriginEntity origin = originService.getById(originNo);

        return R.ok().put("origin", origin);
    }

    @RequestMapping("/save")
    @RequiresPermissions("origin:origin:save")
    public R save(@RequestBody OriginEntity origin){
		originService.save(origin);

        return R.ok();
    }

    @RequestMapping("/update")
    @RequiresPermissions("origin:origin:update")
    public R update(@RequestBody OriginEntity origin){
		originService.updateById(origin);

        return R.ok();
    }

    @RequestMapping("/delete")
    @RequiresPermissions("origin:origin:delete")
    public R delete(@RequestBody Integer[] originNos){
		originService.removeByIds(Arrays.asList(originNos));

        return R.ok();
    }

}
